package com.amoyt.project.controller.web;

import com.amoyt.project.constants.ResponseConstants;
import com.amoyt.project.domain.dto.query.ArticlePageQuery;
import com.amoyt.project.domain.res.Result;
import com.amoyt.project.service.admin.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date: 2025/8/25
 * @Time: 16:38
 * @Author: TQ_QT
 * @Description: 公告新闻
 */
@RestController
@RequestMapping("/web/notice")
@Tag(name = "公告查看公共接口",description = "公告新闻接口")
public class NoticeController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/list-n")
    @Operation(summary = "公示列表",method = "GET")
    public Result list(ArticlePageQuery query) {
        if (query == null || query.getPage() == null || query.getPageSize() == null){
            return Result.error(ResponseConstants.SYSTEM_ERROR);
        }
        query.setCategory(ArticlePageQuery.CATEGORY_PUBLICITY);
        query.setIsOpen(ArticlePageQuery.IS_OPEN);
        query.setIsPublished(ArticlePageQuery.IS_PUBLISHED);
        return articleService.list(query);
    }

    @GetMapping("/detail-n-new/{articleId}")
    @Operation(summary = "公示详情",method = "GET")
    public Result detail(@PathVariable String articleId) {
        if (articleId == null){
            return Result.error(ResponseConstants.SYSTEM_ERROR);
        }
        return articleService.queryArticleDetailNew(articleId);
    }

    /**
     * 通知列表
     * @param query
     * @return
     */
    @GetMapping("/list-p")
    @Operation(summary = "通知列表",method = "GET")
    public Result listP(ArticlePageQuery query) {
        if (query == null || query.getPage() == null || query.getPageSize() == null){
            return Result.error(ResponseConstants.SYSTEM_ERROR);
        }
        query.setCategory(ArticlePageQuery.CATEGORY_NOTICE);
        query.setIsOpen(ArticlePageQuery.IS_OPEN);
        query.setIsPublished(ArticlePageQuery.IS_PUBLISHED);
        return articleService.list(query);
    }

    /**
     * 通知详情
     * @param articleId
     * @return
     */
    @GetMapping("/detail-p-new/{articleId}")
    @Operation(summary = "通知详情",method = "GET")
    public Result detailP(@PathVariable String articleId) {
        if (articleId == null){
            return Result.error(ResponseConstants.SYSTEM_ERROR);
        }
        return articleService.queryArticleDetailNew(articleId);
    }

}
